package com.edu.dao.impl;

import com.as.util.DBUtil;
import com.edu.dao.UserDao;
import com.edu.domain.User;

/**
 * dao层不再处理异常，因为异常要返回给service，用于事务管理
 * 用户数据访问层接口实现
 * 描述：
 * 创建人：飘
 * 创建时间：2024/10/31
 **/
public class UserDaoImpl implements UserDao {

    @Override
    public int saveUser(User user) throws Exception {
        String sql="insert into user(userId,password,userName,userSex) values(?,?,?,?)";
        int result=0;//正常
        try {
            DBUtil.executeUpdate(sql,user.getUserId(),user.getPassword(),user.getUserName(),user.getUserSex());
        }
        catch (Exception e)
        {
            e.printStackTrace();
            result=1;
        }

        return result;
    }

    @Override
    public User getUserByIdByPass(User user) throws Exception {
        String sql="select * from user where userid=? and password=?";
        return DBUtil.executeOne(User.class,sql,user.getUserId(),user.getPassword());
    }

    @Override
    public User getUserById(String userId) throws Exception {
        String sql="select * from user where userid=?";
        return DBUtil.executeOne(User.class,sql,userId);
    }
}
